@extends('content')

@section('content')
<div style="margin-left:20px;margin-right:20px;">
<div style="margin-top:20px;">
	<div style="float:left;width:200px;">
		<form class="bs-example bs-example-form" role="form" action="/module/select" method="post">
				<input type="hidden" name="_token" value="{{ csrf_token() }}" />
			 <div class="input-group input-group-sm" >
					 <input type="text" class="form-control" placeholder="请输入模块名称" name="like" value="{{ $like }}" style="width:150px;">
						<button type="submit" class="btn btn-primary btn-info  btn-sm">查询</button>
			 </div>
	 </form>
	</div>
	<div style="float:right;">	<button type="button" id="create" class="btn btn-primary btn-info btn-sm">添加新模块</button></div>
</div>
<div style="height:50px;"></div>
<table class="table table-striped table-hover table-bordered font table-condensed">
	<thead>
		<tr class="th">
			<th>序号</th>
			<th>模块名称</th>
			<th>模块描述</th>
			<th>上级模块</th>
			<th>模块指向</th>
			<th>创建时间</th>
			<th colspan="2">操作</th>
		</tr>
	</thead>
	<tbody>
		@for($i = 0; $i < count($data); $i++)
		<tr>
			<td>{!! ($data->currentPage() - 1) * 10 +$i+1 !!}</td>
			<td>{{ $data[$i]->name }}</td>
			<td>{{ $data[$i]->description }}</td>
			<td>{{ $data[$i]->parentName }}</td>
			<td>{{ $data[$i]->href }}</td>
			<td>{{ $data[$i]->created_at }}</td>
			<td><button type="button" onclick="edit({{ $data[$i]->id }})" class="btn btn-warning btn-sm">修改</button></td>
			<td><button type="button" onclick="del({{ $data[$i]->id }})" class="btn btn-danger btn-sm">删除</button></td>
		</tr>
		@endfor
	</tbody>
</table>
  <div align="right">{!! $data->render() !!}</div>
</div>
@stop
@section('js')
<script type="text/javascript">

	$('#create').on('click',function(){
		window.location.href = '/module/create';
	});

	// 修改操作

	function edit(id){
		window.location.href= '/module/edit/'+id;
	}

	// 删除操作
	function del(id){
	  var com =confirm('确定要删除吗?');
	      if(com != true)
	      {
	          return;
	      }
	      else {
	          $.ajax({
	              type: 'get',
	              url: '/module/del',
	              data: {
	                  'id':id
	              },
	              dataType: 'json',
	              success: function(data) {
	                  alert(data);
	                  location.reload();
	              },
	              error: function(data) {
	                  console.log('error' + data);
	              }
	          });
	          return;
	      }
	  return;
	}
</script>
@stop
